import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Index from '../views/Index'
import Checkout from '../views/Account/Checkout.vue'
import store from '../store'

import shop from './shop'
import account from './account'



Vue.use(VueRouter)

const routes = [{
    path: '/',
    // name: 'Home',
    component: Home,
    children: [{
        path: '/',
        component: Index,
      },
      ...shop,
      ...account,
    ]
  },
 


]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  let user = store.state.user.user;
  let {
    path
  } = to;
  if (path.indexOf('/home/user') != -1) {
    for(let i=0;i<user.length;i++){
      if(user[i].isonline){
        next()
        return false;
      }
    }
    next('/home/login')
  } else {
    next()
  }

})

export default router